<template>
  <div class="filelist-container">
    <!-- 上传、新建、删除和搜索按钮 -->
    <el-row
      :gutter="24"
      
      justify="space-between"
      style="margin-left: 0px"
    >
    <div style="display:flex;justify-content: center;">
      <el-input
        v-model="searchValue"
        clearable
        placeholder="搜索文件名或类型"
        size="small"
        style="width: 600px; margin-right: 10px;max-height:32px"
        @keypress.native.enter="handSearch"
        @clear="handClearSearch"
      >
        <el-select
          v-model="fileTypeValue"
          clearable
          @change="handleToggleFileType"
          slot="prepend"
          style="width: 82px"
          placeholder="类型"
        >
          <el-option
            v-for="(item, index) in fileTypeOption"
            :key="index"
            :label="item.name"
            :value="item.value"
          ></el-option>
        </el-select>
        <el-button
          slot="append"
          size="small"
          icon="el-icon-search"
          @click="handSearch"
        ></el-button>
      </el-input>
      </div>
      <div v-if="isSearch">搜索列表</div>
      <div v-else style="margin-top:5px">
        <el-button
          v-if="showUpload"
          type="primary"
          size="small"
          icon="el-icon-upload"
          @click="showUploadDialog"
          class="media-margin-bottom-upload"
        >上传文件</el-button>
        <el-button
          type="primary"
          size="small"
          icon="el-icon-plus"
          class="medie-margin-left"
          :disabled="!!treePath.length && treePath[0].id <= 0"
          @click="
            {
              modalType = '新建文件夹';
              dialogUpperVisible = true;
            }
          "
        >新建文件夹</el-button>
        <el-button-group
          v-if="multipleSelection.length && !isShareCenter"
          style="margin-left: 10px"
          class="media-margin-left-group"
        >
          <el-button
            type="default"
            size="small"
            icon="el-icon-share"
            :disabled="multipleSelection.some((item) => item.id <= 0)"
            @click="changeMultipleFileStatus(1)"
          >共享文件</el-button>
          <el-button
            type="default"
            size="small"
            icon="el-icon-user"
            :disabled="multipleSelection.some((item) => item.id <= 0)"
            @click="dialogShareVisible = true"
          >指定分享</el-button>
          <el-button
            type="default"
            size="small"
            icon="el-icon-close-notification"
            :disabled="multipleSelection.some((item) => item.id <= 0)"
            @click="changeMultipleFileStatus(0)"
          >取消共享</el-button>
          <el-button
            type="default"
            size="small"
            icon="el-icon-delete"
            :disabled="multipleSelection.some((item) => item.id <= 0)"
            @click="showDeleteConfirm"
          >&nbsp;&nbsp;删除&nbsp;&nbsp;</el-button>
          <el-button
            type="default"
            size="small"
            icon="el-icon-edit"
            :disabled="multipleSelection.length !== 1 || multipleSelection.some((item) => item.id <= 0)"
            @click="handleClickRename"
          >重命名</el-button>
          <el-button
            type="default"
            size="small"
            icon="el-icon-download"
            :disabled="multipleSelection.some((item) => item.id <= 0 || item.title   )"
            @click="handleClickDownload"
          >下载</el-button>
        </el-button-group>
      </div>
    </el-row>

    <div class="file-path">
      <!-- 如果搜索显示搜索结果 -->
      <el-alert
        v-if="isSearch"
        :title="`共找到${total}个结果`"
        type="info"
        close-text="取消搜索"
        @close="handClearSearch"
        show-icon
      >
      </el-alert>

      <!-- 显示文件层级路径 -->
      <el-row
        v-else
        type="flex"
        align=""
      >
        <span
          v-if="!treePath.length"
          class="path-name"
        >全部文件</span>
        <template v-else>
          <a
            href="#"
            class="path-name path-active"
            @click="onBackPath()"
          >返回上一级</a>
          <el-divider direction="vertical"></el-divider>
          <el-breadcrumb separator-class="el-icon-arrow-right">
            <el-breadcrumb-item><a
                href="#"
                class="path-active"
                @click="onEmptyPath()"
              >全部文件</a></el-breadcrumb-item>
            <el-breadcrumb-item
              v-for="(item, index) in treePath"
              :key="index"
              @click.native="handleTogglePath(index)"
            >{{ item.title }}</el-breadcrumb-item>
          </el-breadcrumb>
        </template>
      </el-row>
    </div>

    <!-- 文件列表显示 -->
    <div class="file-table">
      <el-table
        v-loading="listLoading"
        :data="dataSource"
        :border="false"
        @selection-change="handleSelectionChange"
        @cell-mouse-enter="handleRowMouseMove"
        @cell-mouse-leave="rowSelectedIndex = null"
        style="width: 100%"
      >
        <el-table-column
          type="selection"
          width="42"
        ></el-table-column>
        <el-table-column
          label="名称"
          prop="name"
          min-width="200"
        >
          <template slot-scope="{ row }">
            <image-type
              :width="32"
              :fileType="fileType(row)"
              @onClickImage="handChangeTreePath(row)"
            >
              <span
                style="
                  display: inline-block;
                  vertical-align: sub;
                  margin-right: 6px;
                "
                @click="handChangeTreePath(row)"
              >{{ row.title || row.filename }}</span>
              <i
                v-if="!isSearch && !isShareCenter && row.is_share"
                class="el-icon-message-solid"
                style="vertical-align: text-top; font-size: 20px; color: orange"
                @click="changeFileStatus(row, 0)"
              ></i>
              <i
                v-if="!isSearch && !isShareCenter && !row.is_share && row.part_share"
                class="el-icon-message-solid"
                style="vertical-align: text-top; font-size: 20px; color: #67c23a"
                @click="changeFileStatus(row, 0)"
              ></i>
              <i
                v-if="
                  row.id > 0 &&
                  row.id === rowSelectedIndex &&
                  !isSearch &&
                  !isShareCenter && 
                  !row.is_share &&
                  !row.part_share
                "
                class="el-icon-bell"
                style="
                  vertical-align: text-top;
                  font-size: 20px;
                  color: #409eff;
                "
                @click="changeFileStatus(row, 1)"
              ></i>
            </image-type>
          </template>
        </el-table-column>
        <el-table-column
          label="文件数量"
          prop="file_num"
          width="150"
        >
          <template slot-scope="{ row }">{{
            row.file_num ? row.file_num + '个' : '-'
          }}</template>
        </el-table-column>
        <el-table-column
          label="创建者"
          prop="username"
          width="150"
        />
        <el-table-column
          label="创建时间"
          prop="create_time"
          width="150"
        >
          <template slot-scope="{ row }">{{
            parseTime(row.create_time, "{y}/{m}/{d} {h}:{i}")
          }}</template>
        </el-table-column>
        <el-table-column
          label="大小"
          align="left"
          prop="size"
          width="120"
        >
          <template
            slot-scope="{ row }"
            v-if="row.id > 0"
          >{{
            row.size | formatFileSize
          }}</template>
        </el-table-column>
        <el-table-column width="60">
          <template slot-scope="{ row }">
            <el-dropdown size="small" placement="bottom" @command="value => handleCommand(value, row)" v-if="row.id > 0">
              <span class="el-dropdown-link"> <i class="el-icon-more el-icon--right"></i>  </span>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item command="edit" :disabled="!!row.title || !canEditOnlyOffice.includes(row.type)" icon="el-icon-edit">在线编辑</el-dropdown-item>
                <el-dropdown-item command="download" :disabled="!!row.title" icon="el-icon-download">下载</el-dropdown-item>
                <el-dropdown-item v-if="!isShareCenter" command="delete" icon="el-icon-delete">删除</el-dropdown-item>
                <el-dropdown-item v-if="isTaskCenter || isInfoReport" command="push" icon="el-icon-share">{{ row.is_msg ? '取消推送': '推送' }}</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页 -->
      <pagination
        class="pageWrapper"
        v-show="total > 0"
        :total="total"
        :layout="'total, prev, pager, next'"
        :page.sync="listQuery.page"
        :limit.sync="listQuery.size"
        @pagination="handlePage"
      />

      <!-- 新建文件夹对话框 -->
      <el-dialog
        :title="modalType"
        width="375px"
        :visible.sync="dialogUpperVisible"
      >
        <el-row class="input-box">
          <el-input
            type="text"
            size="small"
            clearable
            placeholder="请输入文件夹名称"
            v-model="catalogName"
            @keyup.enter.native="handCreateCatalog"
          ></el-input>
        </el-row>
        <div
          slot="footer"
          class="dialog-footer"
        >
          <el-button
            size="small"
            @click="dialogFormVisible = false"
          >取 消</el-button>
          <el-button
            size="small"
            type="primary"
            :disabled="!catalogName.length"
            @click="handCreateCatalog"
          >确 定</el-button>
        </div>
      </el-dialog>
    </div>

    <!-- 文件上传对话框 -->
    <el-dialog
      title="上传文件"
      :width="device === 'mobile' ? '90%' : '50%'"
      class="media-table-width"
      :close-on-click-modal="false"
      :visible.sync="dialogUploadVisible"
    >
      <file-upload
        ref="upload"
        :params="uploadParam"
        uploadFieldName="url"
        postUrl="/api/Work/Files/"
        @uploadFile="handFinishUpload"
      ></file-upload>
    </el-dialog>
    <!-- 分享人员选择对话框 -->
    <el-dialog
      :title="`选择所分享人员/群组 - ${getDeleteTootipTitle()}`"
      width="70%"
      :close-on-click-modal="false"
      :visible.sync="dialogShareVisible"
    >
      <user-manager
        ref="userManager"
        :userOuter="false"
        :shareGroup="true"
        :onSelectUsers="handleShareToGroup"
      />
    </el-dialog>
  </div>
</template>
  <script>
import { getFileType, parseTime, uuid } from "@/utils/index.js";
import { saveAs } from 'file-saver'
import JSZip from 'jszip'
import _ from 'lodash'
import {
  queryFileCatalogList,
  queryTaskCenterFileList,
  createFileCatalog,
  deleteFileCatalog,
  updateFileCatalog,
  deleteTaskCenterFile,
  updateTaskCenterFile,
  updateFileInfo,
  queryShareFileList,
  postAppointShare
} from "@/api/document";

export default {
  name: "FileList",
  props: {
    preview: {
      type: Boolean,
      default: false
    },
    isEdit: {
      type: Boolean,
      default: false
    },
    preFileList: {
      type: Array
    }
  },
  watch: {
    treePath(newData) {
      const lastNodes = newData.length && newData.slice(-1);
      this.listQuery.parent = lastNodes ? lastNodes[0].id : null;
      this.requestFileCatalogList();
    }
  },
  computed: {
    device() {
      return this.$store.state.app.device;
    },
    showUpload() {
      const treePath = this.treePath
      return !!treePath.length 
              && (treePath.length > 1 && treePath[0].id == -1  // 共享中心显示上传
                  || treePath[0].id == -3 // 信息快报显示上传
                  || treePath[0].id > 0 // 非基础模块显示上传
              )
    },
    isTaskCenter: function() {
      if (this.treePath.length) {
        return this.treePath[0].id === 0;
      }
    },
    isInfoReport: function() {
      if (this.treePath.length) {
        return this.treePath[0].id === -3;
      }
    },
    isShareCenter: function() {
      if (this.treePath.length) {
        return this.treePath[0].id === -1;
      }
    },
    isMyShare: function() {
      if (this.treePath.length) {
        return this.treePath[0].id === -2;
      }
    },
    // 是否属于智库平台
    isKnowledge() {
      return !!(~location.href.indexOf('knowledge'))
    },
  },
  components: {
    ImageType: () => import("@/components/ImageType"),
    Pagination: () => import("@/components/Pagination"),
    FileUpload: () => import("@/components/FileUpload"),
    UserManager: () =>
      import("@/views/markSys/taskCenter/components/userManager")
  },
  data() {
    return {
      treePath: [],
      dataSource: [], // 文件列表
      multipleSelection: [],
      listQuery: {
        page: 1,
        size: 10
      },
      fileTypeValue: '',
      fileTypeOption: [
        {name: '图片', value: 'image'},
        {name: 'Word', value: 'word'},
        {name: 'Excel', value: 'excel'},
        {name: 'PPT', value: 'ppt'},
        {name: 'PDF', value: 'pdf'},
        {name: '文本', value: 'txt'},
        {name: '音频', value: 'audio'},
        {name: '视频', value: 'vadio'},
      ],
      canEditOnlyOffice: [
        "doc",
        "docx",
        "txt",
        "wps",
        "xls",
        "xlsx",
        "pptx"
      ],
      listLoading: false,
      total: 0,
      dialogUpperVisible: false,
      dialogUploadVisible: false,
      dialogShareVisible: false,
      catalogName: "", // 新建文件夹名称
      searchValue: "", // 搜索值
      rowSelectedIndex: null, // 鼠标移入行index
      uploadParam: null, // 上传文件参数
      isSearch: false, // 是否在搜索文件
      modalType: "新建文件夹"
    };
  },
  mounted() {
    this.requestFileCatalogList();
  },
  methods: {
    /**
     *
     * 多选下载
     */
    handleClickDownload(){
      const rowList = this.multipleSelection
      const zip = new JSZip()
      if(rowList.length > 1){
        const hide = this.$message.success("正在整合~~");
        const fileList = []
        rowList.forEach((item,index) => {
          const { url , filename } = item
          var xhr = new XMLHttpRequest();
          const downloadUrl = '/upload' + url.split('upload')[1]
          xhr.open('GET', downloadUrl, true); // 也可以使用POST方式，根据接口
          xhr.responseType = 'blob'; // 返回类型blob
          xhr.onload = function (e) {
            fileList.push({
              name:filename,
              data:e.target.response
            })
            if(fileList.length == rowList.length){
              fileList.forEach(item =>{
                zip.file(item.name, item.data, {base64: true});
              })
              zip.generateAsync({type:"blob"})
                    .then(function(content) {
                      // see FileSaver.js
                        saveAs(content, fileList[0].name + " 等.zip");
                        hide.close()
                    });
            }
          }
          xhr.send()
        })
        
      }else{
        const { url, filename } = rowList[0];
        let a = document.createElement("a");
        a.download = filename;
        a.href = url;
        a.click();
        window.URL.revokeObjectURL(url);
        }
    },
    parseTime,
    /**
     * 输入关键字搜索文件
     */
    async handSearch() {
      if (!this.searchValue) {
        this.requestFileCatalogList();
        return;
      }
      this.isSearch = true;
      this.listQuery.page = 1;
      this.fetchSeach();
    },
    handleToggleFileType() {
      this.isSearch = true;
      this.listQuery.page = 1;
      this.fetchSeach();
    },
    async fetchSeach() {
      this.listLoading = true;
      const { data: fileList } = await queryTaskCenterFileList({
        search: this.searchValue,
        type: this.fileTypeValue,
        page: this.listQuery.page
      });

      const { count, results } = fileList;

      this.dataSource = results;
      this.total = count;
      this.listLoading = false;
    },
    /**
     * 清空搜索条件
     */
    handClearSearch() {
      this.searchValue = null;
      this.listQuery.page = 1;
      this.requestFileCatalogList();
    },
    /**
     * 分页搜索
     */
    handlePage(val) {
      this.listQuery.page = val.page;
      if (this.isSearch) {
        this.fetchSeach();
      } else {
        this.requestFileCatalogList();
      }
    },

    /**
     * 点击文件夹时进入此目录，更新数据
     * 如果是文件则预览
     */
    handChangeTreePath(item) {
      if (item.title) {
        this.listQuery.page = 1;
        this.treePath.push(item);
      } else {
        this.previewFile(item);
      }
    },
    // 切换目录路径
    handleTogglePath(index) {
      if(this.treePath.length === 1 || index === this.treePath.length -1) return
      this.listQuery.page = 1;
      this.treePath.splice(index + 1)
      this.treePath = [...this.treePath];
    },
    // 跳转到在线office页面
    previewFile(row, isEdit = 0) {
      const { id, type, url } = row;
      const canPreviewOnlyOffice = [
        "doc",
        "docx",
        "wps",
        "txt",
        "xls",
        "xlsx",
        "pptx"
      ];
      if (
        [
          "pdf",
          "bmp",
          "png",
          "gif",
          "jpeg",
          "jpg",
          "mp4",
          "mp3",
          "json",
          "js"
        ].includes(type)
      ) {
        window.open(url, "_blank");
        return;
      } else if (canPreviewOnlyOffice.includes(type)) {
        const { href } = this.$router.resolve({
          name: "FilePreview",
          query: {
            previewType: isEdit,
            fileId: id
          }
        });
        window.open(href, "_blank");
      } else {
        this.$message.info(`所选文件暂不支持在线预览`);
      }
    },
    /**
     * 返回上一级目录
     */
    onBackPath() {
      this.listQuery.page = 1;
      this.treePath.pop();
      this.treePath = [...this.treePath];
    },

    /**
     * 跳转到全部文件夹（清空文件路径）
     */
    onEmptyPath() {
      this.listQuery.page = 1;
      this.treePath = [];
    },

    /**
     * 处理下拉菜单操作
     */
    handleCommand(command, row) {
      switch(command) {
        case 'edit': 
          this.previewFile(row, 1)
          break
        case 'download': 
          this.downloadFile(row)
          break
        case 'delete': 
          this.multipleSelection = [row];
          this.showDeleteConfirm();
          break
        case 'push': 
          this.handlePushFile(row)
          break
      }
    },
    /**
     * 选中行列表
     */
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },

    /**
     * 设置鼠标移入行index
     */
    handleRowMouseMove(row) {
      if (!row.id) return;
      this.rowSelectedIndex = row.id;
    },
    /**
     * 打开上传对话框
     */
    showUploadDialog() {
      const lastNodes = this.treePath.length && this.treePath.slice(-1);
      const param = {
        key: uuid(),
        catalog: lastNodes[0].id
      };
      if(this.isInfoReport) {
        this.uploadParam = { key: uuid(), is_schedule: true, is_msg: true }
      } else {
        this.uploadParam = param
      }
      this.dialogUploadVisible = true;
    },
    /**
     * 上传完成时关闭对话框，刷新数据
     */
    handFinishUpload() {
      this.$refs.upload.clear();
      this.dialogUploadVisible = false;
      this.requestFileCatalogList();
    },
    /**
     * 将文件推送至公告通知
     */
    async handlePushFile(row) {
      const result = await updateTaskCenterFile(row.id, { is_msg: !row.is_msg });
      if(result) {
        this.$message.success(`${row.is_msg ? '取消': ''}推送文件到公告通知成功`)
        this.requestFileCatalogList()
      }
    },
    /**
     * 创建a标签下载文件
     */
    downloadFile(row) {
      const { url, filename } = row;
      let a = document.createElement("a");
      a.download = filename;
      a.href = url;
      a.click();
      window.URL.revokeObjectURL(url);
    },
    /**
     * 批量共享文件
     */
    changeMultipleFileStatus(status) {
      const that = this;
      const noShareFileList = this.multipleSelection.filter(
        item => item.is_share != status || item.part_share != status
      );
      if (!noShareFileList.length) {
        this.$message.info(`所选文件已经${status ? "" : "取消"}共享`);
        return;
      }
      const reqList = noShareFileList.map(item => {
        let result = null;
        return new Promise(async (resolve, reject) => {
          if (item.title) {
            result = await updateFileCatalog(item.id, {
              is_share: status
            });
          } else {
            // 取消/公开文件
            result = await updateTaskCenterFile(item.id, { is_share: status });
          }

          if (result) {
            resolve();
          }
        });
      });
      Promise.all(reqList).then(res => {
        this.multipleSelection = [];
        this.requestFileCatalogList();
        this.$message.success(`${status ? "" : "取消"}共享文件成功`);
      });
    },

    async handleShareToGroup(sureUsersList, groupSelection) {
      const catalogList = [], docList = []
      if(!sureUsersList.length && !groupSelection.length) {
        this.$message.warning('请选择指定分享的人员或群组');
        return
      }
      
      let selection = sureUsersList.length ? sureUsersList : this.getUsersList(groupSelection, [])
      const usersID = selection.map(item => item.id)
      this.multipleSelection.forEach(item => {
        if(item.title) {
          catalogList.push(item.id)
        }
        if(item.filename) {
          docList.push(item.id)
        }
      })
      const { data: { code, msg } } = await postAppointShare({user: usersID, catalog: catalogList, doc: docList})
      if(code === 200) {
        this.$message.success(msg)
        this.dialogShareVisible = false
        this.$refs.userManager.clearSelect()
        this.requestFileCatalogList()
      }else{
        this.$message.error('指定分享失败')
      }
    },
    /**
     * 更改文件状态，如果未公开则点击公开，反之亦然
     */
    async changeFileStatus(row, status) {
      let result = null;
      let tooltip = null;
      // 取消/公开文件夹
      if (row.title) {
        result = await updateFileCatalog(row.id, {
          is_share: status
        });
        tooltip = "共享文件夹";
      } else {
        // 取消/公开文件
        result = await updateTaskCenterFile(row.id, { is_share: status });
        tooltip = "共享文件";
      }
      if (result) {
        if (this.isMyShare) {
          // 如果取消共享最后一个文件，则从第一页显示
          if (this.dataSource.length === 1) {
            this.listQuery.page = 1;
          }
          this.requestFileCatalogList();
        } else {
          this.dataSource.forEach(item => {
            if (item.id === row.id) {
              if(status) {
                item.is_share = true;
                return
              }
              item.part_share = false;
              item.is_share = false;
            }
          });
        }
        this.$message.success(`${status ? "" : "取消"}${tooltip}成功`);
      }
    },
    /**
     * 获取选中文件后对话框标题提示
     */
    getDeleteTootipTitle() {
      if(!this.multipleSelection.length) {
        return ''
      }
      const { title, filename } = this.multipleSelection[0];
      const length = this.multipleSelection.length;
      let name = title || filename;
      if (name.length > 20) {
        let subStr1 = name.substr(0, 10);
        let subStr2 = name.substr(name.length - 8, 8);
        name = subStr1 + "..." + subStr2;
      }
      if (length > 1) {
        return name + "等" + length + "项";
      }
      return name;
    },
    /**
     * 点击重命名按钮
     */
    handleClickRename() {
      const { title, filename } = this.multipleSelection[0]
      let name = ''
      if(title) {
        name = title
      } else {
        const index = filename.lastIndexOf('.')
        name = filename.slice(0, index)
      }
      this.modalType = '重命名';
      this.catalogName = name;
      this.dialogUpperVisible = true;
    },
    /**
     * 显示删除文件或目录对话框
     */
    showDeleteConfirm() {
      this.$confirm(
        "将删除所选文件或文件夹, 是否继续?",
        `提示 - ${this.getDeleteTootipTitle()}`,
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }
      ).then(() => {
        this.handDeleteFileOrCatalog();
      });
    },

    fileType(row) {
      if (row.id > 0) {
        return row.title || !row.url ? "folder" : row.type;
      }else if(row.id === -1) {
        return 'shareCenter'
      }else if(row.id === -2) {
        return 'myShare'
      }else if(row.id === -3) {
        return 'infoReport'
      }else {
        return "task";
      }
    },
    getUsersList(data, result) {
        data.forEach(item => {
          // result = [...result, ...item.user_department]
          item.userinfo.forEach(user => {
            result.push(user);
          });
        });
        return result;
      },
    /**
     * 创建目录，默认以当前目录为父目录ID,如果是根目录则为null
     */
    handCreateCatalog: _.debounce(
      async function () {
        const hide = this.$message("正在配置");
        const lastNodes = this.treePath.length && this.treePath.slice(-1);
        const parent = lastNodes
          ? lastNodes[0].id
            ? lastNodes[0].id
            : null
          : null;
        let result = null;
        if (this.modalType === "重命名") {
          const { id, title, type } = this.multipleSelection[0]
          // 目录
          if(title) {
            result = await updateFileCatalog(id, {
              title: this.catalogName
            });
          } else {
            // 文件
            result = await updateFileInfo(id, {filename: `${this.catalogName}.${type}`})
          }
        } else {
          result = await createFileCatalog({
            title: this.catalogName,
            parent
          });
        }
        if (result) {
          hide.close();
          this.listQuery.page = 1;
          this.dialogUpperVisible = false;
          this.$message.success(`${this.modalType}成功！`);
          this.requestFileCatalogList();
        }
      }, 300
    ),
    /**
     * 发送删除文件或目录请求，成功后刷新列表
     */
    async handDeleteFileOrCatalog() {
      const hide = this.$message("正在删除");
      const list = this.multipleSelection;
      if (list.length === this.dataSource.length) {
        this.listQuery.page = 1;
      }
      const reqList = list.map(item => {
        return new Promise(async (resolve, rejct) => {
          const { id, title, filename } = item;
          let result = null;
          // 属于目录
          if (title && !filename) {
            result = await deleteFileCatalog(id);
          } else {
            result = await deleteTaskCenterFile(id);
          }
          if (result) {
            resolve(result);
          }
        });
      });
      Promise.all(reqList).then(res => {
        hide.close();
        this.$message.success("删除操作成功！");
        this.multipleSelection = [];
        if (this.isSearch) {
          this.fetchSeach();
        } else {
          this.requestFileCatalogList();
        }
      });
    },
    /**
     * 根据目录ID请求列表
     */
    async requestFileCatalogList(isSearch = false) {
      this.listLoading = true;
      this.isSearch = false;
      const { parent, page } = this.listQuery;
      let result = null;
      if (parent === 0 || isSearch) {
        const { data: fileList } = await queryTaskCenterFileList({
          inner: "self",
          page
        });
        result = fileList;
      } else if (parent === -1) {
        const { data: shareList } = await queryShareFileList({ page });
        result = shareList;
      } else if (parent === -2) {
        const { data: myShareList } = await queryShareFileList({
          my_share: 1,
          page
        });
        result = myShareList;
      } else if (parent === -3) {
        const { data: myShareList } = await queryTaskCenterFileList({
          is_schedule: 1,
          page
        });
        result = myShareList;
      } else {
        const { data: fileCatalog } = await queryFileCatalogList({
          ...this.listQuery,
          type: this.fileTypeValue
        });
        result = fileCatalog;
      }
      const { count, results } = result;
      if (!this.treePath.length && this.listQuery.page === 1) {
        let baseList = [
          { id: -1, title: "共享中心", type: "share" },
          { id: -2, title: "我的共享", type: "myShare" }
        ];
        const userRoles = this.$store.state.user.roles
        
        if(!this.isKnowledge) {
          if(userRoles.some(role => role && role.indexOf('管理员') > -1)) {
            baseList = [
              { id: -3, title: "公告通知", type: "infoReport" },
              { id: 0, title: "任务中心", type: "share" },
              ...baseList
            ]
          } else {
            baseList = [
              { id: 0, title: "任务中心", type: "share" },
              ...baseList
            ]
          }
        }
        this.dataSource = [...baseList, ...results];
      } else {
        this.dataSource = results;
      }
      this.total = count;
      this.listLoading = false;
    }
  }
};
</script>
  <style lang="scss">
.filelist-container {
  padding: 20px;
  @media screen and (max-width: 500px){
      .medie-margin-left {
        margin-left:0px !important;
        margin-bottom:5px !important
      }
      .media-margin-left-group{
        margin-left:0px !important;
      }
      .media-margin-bottom-upload{
        margin-bottom:5px !important;
      }
    }
  .file-path {
    margin: 12px 11px 4px;
    .path-name {
      font-size: 14px;
    }
    .path-active {
      color: #409eff;
    }
  }
  .el-alert.is-light .el-alert__closebtn {
    color: #409eff;
    line-height: 20px;
  }
  .el-dialog__footer {
    margin-top: -20px;
  }
  .el-breadcrumb__inner {
    cursor: pointer!important;
    &:hover {
      color: #409eff!important;
    }
  }
  // .el-table__body {

  // .el-checkbox {

  //   margin-left: 12px !important;
  // }
  // .is-checked {
  //   margin-left: 7px !important;
  // }
  // }
}
</style>